package com.liveinstars.im.domain.dao.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.liveinstars.im.common.BaseEntity;
import lombok.Data;
import lombok.ToString;

import java.util.HashMap;

/**
 * <p>
 * 
 * </p>
 *
 * @author 8btc
 * @since 2020-03-03
 */
@Data
@ToString
public class ChatGroup extends BaseEntity {

    private static final long serialVersionUID = 1L;

    //bigClassId的属性
    public final static int TYPE_HOT = 1;
    public final static int TYPE_COIN = 2;
    public final static int TYPE_MARKET = 3;
    public final static int TYPE_PROJECT_OWNER = 4;
    public final static int TYPE_PIRATE = 5;
    public final static int TYPE_OTHER = 6;

    public enum UserLevel {
        USERLEVEL_XIAOBAI("小白", 9),
        USERLEVEL_SHUISHOU("水手", 10),
        USERLEVEL_CHUANYUAN("船员", 31),
        USERLEVEL_DUIZHANG("队长", 11),
        USERLEVEL_FUCHUANZHANG("副船长", 12),
        USERLEVEL_CHUANZHANG("船长", 29),
        USERLEVEL_HAIDAOWANG("海盗王", 14);

        static private HashMap<Integer, UserLevel> m_map = new HashMap<>();

        static {
            for (UserLevel status : UserLevel.values()) {
                m_map.put(status.getType(), status);
            }
        }

        protected String m_value;
        protected int m_type;

        UserLevel(String value, int type) {
            m_value = value;
            m_type = type;
        }

        public String getValue() {
            return m_value;
        }

        public int getType() {
            return m_type;
        }

        public boolean isEqual(UserLevel type) {
            return m_value.equals(type.getValue());
        }

        public static UserLevel getUserLevel(int type) {
            UserLevel tmp = m_map.get(type);
            if(tmp == null) tmp = USERLEVEL_CHUANYUAN;
            return tmp;
        }

        public static boolean matchLevel(int userLevel, int groupUserLevel){
            boolean isMatch = false;
            switch (groupUserLevel){
                case 0:
                    isMatch = true;
                    break;
                case 1:
                    isMatch = userLevel > USERLEVEL_XIAOBAI.m_type;
                    break;
                case 2:
                    isMatch = (userLevel == USERLEVEL_CHUANYUAN.m_type
                            || userLevel == USERLEVEL_DUIZHANG.m_type
                            || userLevel == USERLEVEL_FUCHUANZHANG.m_type
                            || userLevel == USERLEVEL_CHUANZHANG.m_type
                            || userLevel == USERLEVEL_HAIDAOWANG.m_type);
                    break;
                case 3:
                    isMatch = (userLevel == USERLEVEL_DUIZHANG.m_type
                            || userLevel == USERLEVEL_FUCHUANZHANG.m_type
                            || userLevel == USERLEVEL_CHUANZHANG.m_type
                            || userLevel == USERLEVEL_HAIDAOWANG.m_type);
                    break;
                case 4:
                    isMatch = (userLevel == USERLEVEL_FUCHUANZHANG.m_type
                            || userLevel == USERLEVEL_CHUANZHANG.m_type
                            || userLevel == USERLEVEL_HAIDAOWANG.m_type);
                    break;
                case 5:
                    isMatch = (userLevel == USERLEVEL_CHUANZHANG.m_type
                            || userLevel == USERLEVEL_HAIDAOWANG.m_type);
                    break;

                case 6:
                    isMatch = (userLevel == USERLEVEL_HAIDAOWANG.m_type);
                    break;
            }
            return isMatch;
        }
    }

    public final static int AUTHRULE_0 = 0;//不需要验证
    public final static int AUTHRULE_1 = 1;//需要验证

    /**
     * 圈子id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 圈子账号
     */
    private String account;

    /**
     * 圈子名称
     */
    private String name;

    /**
     * 圈子描述
     */
    private String description;

    /**
     * 圈子logo
     */
    private String groupLogo;

    /**
     * 圈子二维码
     */
    private String qrcode;

    /**
     * 圈子标语
     */
    private String slogan;

    /**
     * 圈子等级
     */
    private Integer groupLevel;

    /**
     * 入圈用户等级规则
     */
    private Integer userLevel;

    /**
     * 入圈是否需要验证
     */
    private Integer authRule;

    /**
     * 创建时间
     */
    private Integer createDate;

    /**
     * 圈子创建人
     */
    private Long createById;

    /**
     * 管理员1
     */
    private Long manager1Id;

    /**
     * 管理员2
     */
    private Long manager2Id;

    /**
     * 认证标志位
     */
    private Integer identification;

    /**
     * 热度值
     */
    private Integer hot = 0;

    /**
     * 圈子分类id 1-综合 2-技术 3-项目 4-平台 5-行情 6-挖矿
     */
    private Integer bigClassId;

    /**
     * 群聊组类型 0-是圈子，2-是聊天室用于web qkl123, 3-点聊
     */
    private Integer groupType;

    /**
     * 是否隐藏
     */
    private Boolean hidden;

    private Integer interestId;


    public void setPersonToPersonGroupUserId(Long userId1, Long userId2) {
        if (userId1 > userId2) {
            this.manager1Id = userId1;
            this.manager2Id = userId2;
        } else {
            this.manager1Id = userId2;
            this.manager2Id = userId1;
        }
    }
}
